package system_interface;

import IA.*;
import invoker.Invoker;
import java.util.*;

/**
 *
 * @author Christopher
 */
public class SystemInterface {

    private Invoker invoker;

    public SystemInterface(Invoker invoker) {
        this.invoker = invoker;
    }

    public String browseMenu() {
        return menuToString((Menu) invoker.browseMenu());
    }
    /*
     * takes priceStr as price returns menu in form of
     * name/description/currentPrice/rating
     */

    public String browseMenuByPrice(String priceStr) {
        return menuToString((Menu) invoker.browseMenuByPrice(priceStr));
    }
    /*
     * takes rateStr as rate returns menu in form of
     * name/description/currentPrice/rating
     */

    public String browseMenuByRating(String ratingStr) {
        return menuToString((Menu) invoker.browseMenuByRating(ratingStr));
    }
    /*
     * takes prepStr as prepTime/index
     */

    public void adjustPrepTime(String prepStr) {
        invoker.adjustPrepTime(prepStr);
    }
    /*
     * takes changeStr as name/description/basePrice/dishesAvail/ prepTime/index
     */

    /*
     * removeStr as index
     */

    public void removeItem(String removeStr) {
        invoker.removeItem(removeStr);
    }

    /*
     * takes String in the form of name/description/basePrice/dishesAvail/
     * prepTime
     */
    public void addItem(String itemStr) {
        invoker.addItem(itemStr);
    }

    public String getTableStatus(int TableID) {
        return invoker.getTableStatus(TableID).toString();
    }

    /*
     * Unpacks menu into a string
     */
    public String menuToString(Menu menu) {
        String returnStr = "";
        for (MenuItem item : menu.getList()) {
            returnStr = returnStr.concat(item.toString() + "/");
        }
        if (!returnStr.isEmpty()) {
            return returnStr.substring(0, returnStr.length() - 1);
        } else {
            return returnStr;
        }
    }

    public void setNumberOfTables(String totalNumOfTables) {
        invoker.setNumberOfTables(totalNumOfTables);
    }

    public String getNumberOfTables() {
        return invoker.getNumberOfTables().toString();
    }

    public String GetMostLeastOrdered() {
        return invoker.GetMostLeastOrdered().toString();
    }

    public String getCustomerQueue() {
        String returnStr = "";
        for (Iterator<WaitingParty> itr = invoker.getCustomerQueueIterator(); itr.hasNext();) {
            WaitingParty wP = itr.next();
            returnStr = returnStr.concat(wP.getNumCustomers() + " Customers (waiting for " + wP.getWaitingTime() + " min/");
        }
        if (!returnStr.isEmpty()) {
            return returnStr.substring(0, returnStr.length() - 1);
        } else {
            return returnStr;
        }
    }

    public String getKitchenQueue() {
        String returnStr = "";
        for (Iterator<CookItem> itr = invoker.getKitchenQueueIterator(); itr.hasNext();) {
            CookItem cI = itr.next();
            returnStr = returnStr.concat(cI.getName() + "(Table " + cI.getTableID() + ")/");
        }
        if (!returnStr.isEmpty()) {
            return returnStr.substring(0, returnStr.length() - 1); //get rid of last "/"
        } else {
            return returnStr;
        }
    }

    public String getItemsOnGrill() {
        String returnStr = "";
        for (Iterator<CookItem> itr = invoker.getGrillIterator(); itr.hasNext();) {
            CookItem cI = itr.next();
            returnStr = returnStr.concat(cI.getName() + " (" + cI.getPrepTime() + " min left) " + " (Table " + cI.getTableID() + ")/");
        }
        if (!returnStr.isEmpty()) {
            return returnStr.substring(0, returnStr.length() - 1); //get rid of last "/"
        } else {
            return returnStr;
        }
    }

    public String getAverageCustomerWaitingTime() {
        return invoker.getAverageCustomerWaitingTime() + " min";
    }

    public String getNumberOfCustomersWaiting() {
        return Integer.toString(invoker.getNumberOfWaitingCustomers());
    }

    public String getNumberOfOrdersAtTable(int TableIndex) {
        Integer v = invoker.getOrdersAtTable(TableIndex);
        return v.toString();
    }

    public int getNumberOfCustomersAtTable(int TableIndex) {
        return invoker.getCustomersAtTable(TableIndex);
    }

    public String getTotalNumCustomers() {
        return Integer.toString(invoker.getTotalNumCustomers());
    }

    public String getFoodStatus(int TableID) {
        return invoker.getFoodStatus(TableID);
    }

    public String getAverageCookDeliveryTime() {
        return invoker.getAverageCookDeliveryTime() + " min";
    }

    public String getAveragePrepTime() {
        return invoker.getAveragePrepTime() + " min";
    }
} // end class SystemInterface